package edu.rabbit.demo;

import java.io.File;
import java.util.Calendar;

import edu.rabbit.Database;
import edu.rabbit.DbException;
import edu.rabbit.table.ITable;

public class RabbitDemo {
	
	private static final String DB_NAME = "rabbit.db";
    private static final String TABLE_NAME = "employees";

    private static final String FIRST_NAME_FIELD = "first_name";
    private static final String SECOND_NAME_FIELD = "second_name";
    private static final String DOB_FIELD = "date_of_birth";
    
	public static void main(String args[]) throws DbException{
		
		File dbFile = new File(DB_NAME);
        dbFile.delete();
        
		 // create database and table
		Database db = Database.open(dbFile, true );
		
		 String createTableQuery = "create table " + TABLE_NAME + " (" + SECOND_NAME_FIELD + " text not null primary key , " + FIRST_NAME_FIELD + " text not null, " + DOB_FIELD + " integer not null)";
	     System.out.println();
	     System.out.println(">DB schema queries:");
	     System.out.println();
	     System.out.println(createTableQuery);
	     
	     db.createTable(createTableQuery);
	     
	    
         ITable table = db.getTable(TABLE_NAME);//get Table
	     System.out.println("use "+TABLE_NAME);
	     System.out.println("insert 4 records!");
	     Calendar calendar = Calendar.getInstance();
         calendar.clear();
         
         calendar.set(1989, 01, 01);
         
         table.insert("Yuanyan1", "Cao", calendar.getTimeInMillis());
         table.insert("Yuanyan2", "Cao", calendar.getTimeInMillis());
         table.insert("Yuanyan3", "Cao", calendar.getTimeInMillis());
         table.insert("Yuanyan4", "Cao", calendar.getTimeInMillis());

	     
	     db.close();//close db
		
		
	}
}
